# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function

from ..ops import Max, Ref, Abs, Greater
from ..base import OpsFeature

from .close import Close
from .high import High
from .low import Low

class TR(OpsFeature):
    """Technical Indicator - TR

    - TR = MAX(HIGH - LOW, ABS(REF(CLOSE, 1) - HIGH), ABS(REF(CLOSE, 1) - LOW))
    """
    def _load_internal(self, instrument, start_time, end_time, freq):
        high = High()
        low = Low()
        close = Close()
        v1 = high - low
        v2 = Abs(Ref(close, 1) - high)
        v3 = Abs(Ref(close, 1) - low)
        tr = Greater(Greater(v1, v2), v3)
        return tr.load(instrument, start_time, end_time, freq)
